package io.gitee.hchaojie.day08.thread.exam2;

public class Producer implements Runnable {
    private Factory factory;

    private int id = 0;

    public Producer(Factory factory) {
        this.factory = factory;
    }

    @Override
    public void run() {
        while (true) {
            // 每过 0 - 20ms，往工厂里面放一个产品
            try {
                Thread.sleep((long) (Math.random() * 20));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            factory.put(Integer.valueOf(id++));
        }
    }
}
